package com.sjy.web.controller.ship;

import com.sjy.common.annotation.Log;
import com.sjy.common.core.controller.BaseController;
import com.sjy.common.core.domain.AjaxResult;
import com.sjy.common.core.page.TableDataInfo;
import com.sjy.common.enums.BusinessType;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.ship.domain.ShipWorkLine;
import com.sjy.ship.domain.vo.ShipWorkLineVo;
import com.sjy.ship.service.IShipWorkLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 船作业线工作记录Controller
 * 
 * @author lzm
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/ship/line")
public class ShipWorkLineController extends BaseController
{
    @Autowired
    private IShipWorkLineService shipWorkLineService;

    /**
     * 查询船作业线工作记录列表
     */
    @PreAuthorize("@ss.hasPermi('ship:line:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipWorkLineVo shipWorkLine)
    {
        startPage();
        List<ShipWorkLineVo> list = shipWorkLineService.selectShipWorkLineVoList(shipWorkLine);
        return getDataTable(list);
    }

    /**
     * 导出船作业线工作记录列表
     */
    @PreAuthorize("@ss.hasPermi('ship:line:export')")
    @Log(title = "船作业线工作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShipWorkLineVo shipWorkLine)
    {
        List<ShipWorkLineVo> list = shipWorkLineService.selectShipWorkLineVoList(shipWorkLine);
        ExcelUtil<ShipWorkLineVo> util = new ExcelUtil<ShipWorkLineVo>(ShipWorkLineVo.class);
        util.exportExcel(response, list, "船作业线工作记录数据");
    }

    /**
     * 获取船作业线工作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ship:line:query')")
    @GetMapping(value = "/{shipWorkId}")
    public AjaxResult getInfo(@PathVariable("shipWorkId") Long shipWorkId)
    {
        return success(shipWorkLineService.selectShipWorkLineByShipWorkId(shipWorkId));
    }

    /**
     * 新增船作业线工作记录
     */
    @PreAuthorize("@ss.hasPermi('ship:line:add')")
    @Log(title = "船作业线工作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ShipWorkLine shipWorkLine)
    {
        shipWorkLineService.insertShipWorkLine(shipWorkLine);
        return success();
    }

    /**
     * 修改船作业线工作记录
     */
    @PreAuthorize("@ss.hasPermi('ship:line:edit')")
    @Log(title = "船作业线工作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ShipWorkLine shipWorkLine)
    {
        shipWorkLineService.updateShipWorkLine(shipWorkLine);
        return success();
    }

    /**
     * 删除船作业线工作记录
     */
    @PreAuthorize("@ss.hasPermi('ship:line:remove')")
    @Log(title = "船作业线工作记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shipWorkIds}")
    public AjaxResult remove(@PathVariable Long[] shipWorkIds)
    {
        return toAjax(shipWorkLineService.deleteShipWorkLineByShipWorkIds(shipWorkIds));
    }
}
